package cn.chengpengper.fragmentUpload.controller;

import cn.chengpengper.fragmentUpload.common.Result;
import cn.chengpengper.fragmentUpload.common.ResultUtils;
import cn.chengpengper.fragmentUpload.dto.ShardUploadCompleteRequest;
import cn.chengpengper.fragmentUpload.dto.ShardUploadDetailResponse;
import cn.chengpengper.fragmentUpload.dto.ShardUploadInitRequest;
import cn.chengpengper.fragmentUpload.dto.ShardUploadPartRequest;
import cn.chengpengper.fragmentUpload.service.ShardUploadService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/*@formatter:off*/

/**
 * ____________________
 * < 神兽护体，永无bug! >
 * --------------------
 *
 * @author catwing
 * @version v1.0.0
 * @date 2024/12/7 22:42
 * @description 分片上传接口
 */

/*@formatter:on*/

@RestController
@RequestMapping("/shardUpload")
public class ShardUploadController {

    @Resource
    private ShardUploadService shardUploadService;

    @PostMapping("/v1/initUploadTask")
    public Result<Long> initUploadTask(@RequestBody ShardUploadInitRequest request) {
        Long uploadTaskId = shardUploadService.initUploadTask(request);
        return ResultUtils.ok(uploadTaskId);
    }

    @PostMapping("/v1/uploadPart")
    public Result<Boolean> uploadPart(ShardUploadPartRequest request) {
        shardUploadService.uploadPart(request);
        return ResultUtils.ok(Boolean.TRUE);
    }

    @PostMapping("/v1/complete")
    public Result<Boolean> complete(@RequestBody ShardUploadCompleteRequest request) {
        shardUploadService.complete(request);
        return ResultUtils.ok(Boolean.TRUE);
    }

    @GetMapping("/v1/detail")
    public Result<ShardUploadDetailResponse> detail(@RequestParam Long shardUploadTaskId) {
        return ResultUtils.ok(shardUploadService.detail(shardUploadTaskId));
    }

}
